<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<div id="candidate" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    <?=$this->lang->line("Profile")?> > <?=$this->lang->line("Profile")?>
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24"><?=$this->lang->line("TodayIS")?> <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="detail-menu">
        <?php if($type==4){?>
            <div class="active1 single-menu menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 detail-active menu" id="menu2"><?=$this->lang->line("Archived")?></div>
            <div class="active3 single-menu menu" id="menu3"><?=$this->lang->line("Trash")?></div>
        <?php }else if($type==5){?>
            <div class="active1 single-menu menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 single-menu menu" id="menu2"><?=$this->lang->line("Archived")?></div>
            <div class="active3 detail-active menu" id="menu3"><?=$this->lang->line("Trash")?></div>
        <?php }else{?>
            <div class="active1 detail-active menu" id="menu1"><?=$this->lang->line("Normal")?></div>
            <div class="active2 single-menu menu" id="menu2"><?=$this->lang->line("Archived")?></div>
            <div class="active3 single-menu menu" id="menu3"><?=$this->lang->line("Trash")?></div>
        <?php }?>
        <div style="width:0px;"></div>
    </div>
    <div class="list-div" style="margin-top:0px;">
        <?php echo form_open('profile/index'); ?>
        <table class="top-table">
            <tr>
                <td><?=$this->lang->line("Profile")?><input type="hidden" value="<?=$ordername?>" name="ordername" id="ordername" /></td>
                <td width="240" class="center"><input type="text" placeholder="<?=$this->lang->line("searchmsg")?>" 
                    name="condition" value="<?=$condition?>"/></td>
                <td width="90" class="center"><input type="submit" value="<?=$this->lang->line("Search")?>" /></td>
                <?php if($this->session->userdata('department') == 1){?>
                <td width="110" class="center"><input type="button" value="<?=$this->lang->line("New")?>" id="new"/></td>
                <?php }?>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table class="list-table">
            <tr>
                <th class="order" ordername="name"><?=$this->lang->line("name")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="120" class="order" ordername="createtime"><?=$this->lang->line("CreateTime")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="120" class="order" ordername="updatetime"><?=$this->lang->line("UpdateTime")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100"><?=$this->lang->line("Source")?></th>
                <?php if($this->session->userdata('department') == 1){?>
                <?php if($type!=4 && $type != 5){?>
                <th width="60"></th>
                <?php }?>
                <?php if($type==0){?>
                <th width="60"></th>
                <?php }?>
                <th width="60"></th>
                <?php if($type==5){?>
                <th width="60"></th>
                <?php }}?>
            </tr>
            <?php foreach ($profile as $key => $value) {?>
            <tr>
                <td><a href="<?=base_url('profile/detail_profile/'.$value['id'])?>"><?=$value['name']?></a></td>
                <td><?=date('M d,Y H:m:s',$value['createtime'])?></td>
                <td><?=date('M d,Y H:m:s',$value['updatetime'])?></td>
                <td><input type="text" value="<?=$value['source']?>" name="source" profileid="<?=$value['id']?>" style="width:90px;"/></td>
                <?php if($this->session->userdata('department') == 1){?>
                <?php if($type!=4 && $type != 5){?>
                <td>
                    <a href="javascript:void(0)" class="buttona detail" candidateid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/detail.png"/><?=$this->lang->line("Edit")?>
                    </a>
                </td>
                <?php }?>
                <?php if($type==0){?>
                <td>
                    <a href="javascript:void(0)" class="buttona trash" profileid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/delete.png"/><?=$this->lang->line("Trash")?>
                    </a>
                </td>
                <?php }?>
                <td>
                    <?php if($type!=4&&$type!=5){?>
                        <a href="javascript:void(0)" class="buttona archived" profileid="<?=$value['id']?>">
                            <img src="<?=base_url()?>resource/img/archived.png"/><?=$this->lang->line("Archived")?>
                        </a>
                    <?php }else if($type==4||$type==5){?>
                        <a href="javascript:void(0)" class="buttona restore" profileid="<?=$value['id']?>">
                            <img src="<?=base_url()?>resource/img/restore.png"/><?=$this->lang->line("Restore")?>
                        </a>
                    <?php }?>
                </td>
                <?php if($type==5){?>
                <td>
                    <a href="javascript:void(0)" class="buttona delete" profileid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/delete.png"/><?=$this->lang->line("Delete")?>
                    </a>
                </td>
                <?php }}?>
            </tr>
            <?php }
            if(count($profile) == 0){?>
            <tr>
                <td colspan="6">
                    NO DATA
                </td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="6" class="pagination">
                    <?php echo $page;?>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
$(".menu").click(function(){
    var id = $(this).attr("id");
    var url = "<?=base_url()?>profile/index";
    if(id == "menu1"){
        url += "?type=0";
    }else if(id == "menu2"){
        url += "?type=4";
    }else if(id == "menu3"){
        url += "?type=5";
    }
    location.href = url;
});    
    
$("input[name='source']").focus(function(){
}).blur(function(){
    var id = $(this).attr("profileid");
    var source = $(this).val();
    $.ajax({
        type:'post',
        url:'<?=base_url()?>profile/updatesource',
        data:{
            "id":id,
            "source":source
        }
    });
});

$("#new").click(function(){
//    var iTop = (document.body.clientHeight-30-600)/2; //获得窗口的垂直位置;
//    var iLeft = (document.body.clientWidth-10-800)/2; //获得窗口的水平位置;
//    window.open('<?//=base_url("profile/select_order")?>','_blank',
//    'width=800,height=600,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,top='+iTop+',left='+iLeft); 
    location.href = "<?=base_url("profile/new_profile")?>";
});

var url = '<?=base_url()?>profile/index';
var order = "<?=$ordername?>";
var orders = order.split(" ");
$("th").each(function(){
    var ordername = $(this).attr("ordername");
    if(orders[0] == ordername){
        $(this).children("img").attr("src","<?=base_url()?>resource/img/arrow_"+orders[1]+".png");
    }
});

$(".archived").click(function(){
    var profileid = $(this).attr("profileid");
    location.href = "<?=base_url()?>profile/archived?id="+profileid+"&type=0";
});

$(".restore").click(function(){
    var profileid = $(this).attr("profileid");
    location.href = "<?=base_url()?>profile/restore?id="+profileid+"&type=0";
});

$(".detail").click(function(){
    var id = $(this).attr("candidateid");
    var url = '<?=base_url()?>profile/profile_edit?id='+id;
    location.href=url;
});

$(".trash").click(function(){
    var profileid = $(this).attr("profileid");
    location.href = "<?=base_url()?>profile/archived?id="+profileid+"&type=3";
});

$(".delete").click(function(){
    if(confirm("Are you sure delete this profile?")){
        var profileid = $(this).attr("profileid");
        location.href = "<?=base_url()?>profile/delete/"+profileid;
    }
});
</script>
